'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 用户相关
 * @author sundbcn@gmail.com (sun debing)
 */

var Code = require('../../../consts/code');
var chatType = require('../../../consts/chatType');
var chatMgr = require('../../../mgr/chatMgr');
var taskService = require('../../../services/taskService.js');
var PlayerManager = require('../../../libs/playerManager.js');

module.exports = function (app) {
    return new Handler(app);
};

var Handler = function (app) {
    this.app = app;
};

/**
 * 获取用户信息
 * @param  {[type]}   msg     [description]
 * @param  {[type]}   session [description]
 * @param  {Function} next    [description]
 * @return {[type]}           [description]
 */
Handler.prototype.sendSystem = function (msg, session, next) {
    var content = msg.query.content;
    if (!content) {
        return next(null, {
            code: Code.PARAM_ERROR
        });
    }

    var role_id = session.uid;
    var player_manager = new PlayerManager(role_id);

    var param = {
        role_id: 0,
        type: chatType.SYSTEM,
        name: '',
        job: 0,
        msg: content
    };
    chatMgr.sendWorld(param, function (err, fails) {
        if (err) {
            console.error('send message to world error: %j, fail ids: %j', err, fails);
            return next(null, {
                code: Code.FAIL
            });
        }
        return next(null, {
            code: Code.OK
        });
    });
};
